<?php
	class messClass{
//		error_reporting(0);抑制所有报错
		function __construct(){

			@$bb=$_GET['func'];
				if($bb =="delete"){
					$this->delete();
				}
				elseif($bb =="modify"){
					$this->modify();
				}
				elseif($bb =="modify_1"){
					$this->modify_1();
				}
				elseif($bb =="query"){
					$this->query();
				}
				elseif($bb =='home_page'){
					$this->home_page();
				}
				elseif($bb =='logout'){
					$this->logout();
				}elseif($bb =='mess'){
					$this->mess();
				}else{
					$this->home();
				}
		}
		
		function mess(){
			$page_size=3;
			$sql2=mysql_query("SELECT count(id) FROM test_user");
			$rel2=mysql_fetch_row($sql2);
			$total=$rel2[0];
			$page_max=ceil($total/$page_size);
	        if(!isset($_GET["page_num"]) || $_GET['page_num']>$page_max || $_GET['page_num']<1) {
	       	    $page_num=1;
	        }else{
	       	    $page_num=$_GET["page_num"];
	        }
		    $front=($page_num-1)*$page_size;
			$sql=mysql_query("select * from test_user limit $front,$page_size");							
			$rel=mysql_fetch_object($sql);
			
     		require_once('./design.php');
        }
		
			function delete(){
				$id=$_GET['id'];
				$sql="delete from test_user where id='$id'";
				$rel=mysql_query($sql);
				if($rel){
					echo "<script>alert('删除成功');window.location.href='./index.php?action=messClass&func=mess';</script>";
				}else{
					echo "<script>alert('删除失败');history.back();</script>";
				}
			}
		
			function modify(){
				$id=$_GET['id'];
				$sql=mysql_query("select * from test_user where id=$id");
				$rel=mysql_fetch_object($sql);
				include_once("./xiugai.php");	
			}
			function modify_1(){
			   $id=$_GET['id'];
			   $email=$_POST['email'];
			   $title=$_POST['title'];
			   $content=$_POST['content'];
			   $rel=mysql_query("update test_user set  email='$email',title='$title',content='$content' where id='$id'");
			   
			   if($rel){
			   	   echo "<script>alert('修改成功');window.location.href='./index.php?action=messClass&func=mess';</script>";
			   }else{
			   	   echo "<script>alert('修改失败');window.location.href='./index.php?action=messClass&func=mess';</script>";
			   }
			  
			}
        function query(){
        	$keywords=$_POST['keywords'];
			$page_size=10;
			$sql2=mysql_query("SELECT count(id) FROM test_user");
			$rel2=mysql_fetch_row($sql2);
			$total=$rel2[0];
			$page_max=ceil($total/$page_size);
	        if(!isset($_GET["page_num"]) || $_GET['page_num']>$page_max || $_GET['page_num']<1) {
	       	    $page_num=1;
	        }else{
	       	    $page_num=$_GET["page_num"];
	        }
		    $front=($page_num-1)*$page_size;
			$sql=mysql_query("select * from test_user where  email like '%$keywords%'  or  id like '%$keywords%'  or title like '%$keywords%'  or content like '%$keywords%' limit $front,$page_size");
		    if($keywords==""){
		    	echo "<script>alert('查找的内容不能为空');</script>";
		    }
			$rel=mysql_fetch_object($sql);
     		 require_once('./design.php');
        }
        
		function home_page(){
			require_once('./index_2.php  ');
		}
		
		function logout(){
			session_start();
			session_destroy();
			echo "<script>alert('注销成功');window.location.href='../';</script>";
			
		}
		function home(){
			session_start();
			if(@$_SESSION['username']){
				require_once("./index_2.php");
			}else{
				echo "<script>alert('非法登录');window.location.href='../index.php?action=welcome&func=admin';</script>";
			}
		}
	
		
		

	
	
	
	}
	
	?>